﻿using Company.Application.Setting.Models;
using Company.Application.Share.Config;
using Company.Core.Attributes;
using Company.Core.Config;
using Company.Core.Helpers;
using Company.Core.IOC;
using Company.Hardware.Camera;
using Company.Hardware.Detector;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Company.Application.Setting.Services
{
    /// <summary>
    /// 配置管理类（用于从配置文件中读取所有配置信息，然后提供给Provider）
    /// </summary>
    [ExposedService]
    public class SettingManager
    {
        private readonly IConfigManager _configManager;
        public SettingManager(IConfigManager configManager)
        {
            _configManager = configManager;
            Initialize();
        }

        public SettingModel Config { get; set; }

        /// <summary>
        /// 初始化，读取配置文件
        /// </summary>
        public void Initialize()
        {
            Config = _configManager.Read<SettingModel>(ConfigKeys.SystemConifg) ?? new SettingModel();
        }

        /// <summary>
        /// 写入到配置文件
        /// </summary>
        public void Save()
        {
            _configManager.Write(ConfigKeys.SystemConifg, Config);
        }
    }
}
